package com.ruoyi.gateway.config;

public class TaxUtil {
 
    // 假设的税率表，实际需根据实际税率表调整
    private static final double[][] TAX_TABLE = {
        {5000, 0.03, 0},
        {7000, 0.1, 210},
        {12000, 0.2, 1410},
        {25000, 0.25, 3140},
        {35000, 0.3, 5840},
        {55000, 0.35, 11140},
        {80000, 0.45, 17440}
        // 税率表需要包括足够的数据以覆盖所有可能的工资范围
    };
 
    public static double calculateTax(double salary) {
        double tax = 0;
        for (double[] bracket : TAX_TABLE) {
            if (salary > bracket[0]) {//8780>5000
                //8780-5000=3780
                double deductibleAmount = Math.max(salary - bracket[0], 0);
                //3780*0.03-0=113.40
                tax += deductibleAmount * bracket[1] - bracket[2];
                //8780-3780=5000
                salary -= bracket[0];
            }
        }
        return tax;
    }
 
    public static double accumulateTax(double[] salaries) {
        double totalTax = 0;
        for (double salary : salaries) {
            totalTax += calculateTax(salary);
        }
        return totalTax;
    }
 
    public static void main(String[] args) {
        double[] salaries = {15000}; // 示例工资数组
        Double totalTax = accumulateTax(salaries);
        String format = String.format("%.2f", totalTax);
        System.out.println("累计扣税金额: " +format);
    }
}